<?php


require_once '../conf.php';
require_once PATH_TO_SOURCE.'/model/model.php';
require_once PATH_TO_SOURCE.'/controller/controller.php';


class route{
	
	private $db;
	private $type;
		
	function __construct($url){
		$this->db = pg_connect("host='".DB_HOST."' dbname='".DB_NAME."' user='".DB_USER."' password='".DB_PASS."'");
		
		$query = "Select id,type from route  
					where url = '".$url."'";
		$result = pg_query($this->db,$query);
		$row = pg_fetch_all($result);
		
		if($row[0]['type'] == 'product'){
			
			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/product.php';
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
					
		}else if ($row[0]['type'] == 'article_main'){
			
			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/articleMain.php';
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
			
		}else if ($row[0]['type'] == 'article'){
			
			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/article.php';
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
			
		}else if($row[0]['type'] == 'category'){

			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/category.php';
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
				
		}else if($row[0]['type'] == 'category_main'){

			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/categoryMain.php';
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
			
		}else if($row[0]['type'] == 'index'){
			
			require_once PATH_TO_SOURCE.'/view/state/header.php';
			require_once PATH_TO_SOURCE.'/view/index.php';
			// Nie mam zielonego pojecia czemu ale footer musi byc w samym index./.
			//require_once PATH_TO_SOURCE.'/view/state/footer.php';
			
		}else{
		
			require_once PATH_TO_SOURCE.'/view/state/header.php';
			echo "a teraz wpisalismy jakies glupoty";
				$this->article = 'jakies glupoty';
				echo "</br> Podany zostal w adresie:".$url;
			require_once PATH_TO_SOURCE.'/view/state/footer.php';
			/*
			 * w tej instrukcji mozna wpisac np. przekierowania na gluwna strone 
			 * dobre pod seo bo nawet zle linki nie beda sie marnowaly
			 */
		}
		
	}
	
}

$url = $_GET['url'];
$go = new route($url);

?>
